package com.atguigu.cloud.controller;/**
 * @Auter zzh
 * @Date 2024/11/13
 */

import com.atguigu.cloud.entities.Merchant;
import com.atguigu.cloud.sevice.Impl.MerchantServiceImpl;
import com.atguigu.cloud.tool.load.page.PaginationResult;
import com.atguigu.cloud.tool.resp.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.controller
 * @className: merchantcontrollor
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/13 18:26
 * @version: 1.0
 */
@Tag(name = "商家表", description = "商家表增删改")
@RestController
public class Merchantcontrollor {
    @Resource
    MerchantServiceImpl merchantService;

    //增加商家
    @PostMapping(value = "/merchant/add")
    @Operation(summary = "添加商家", description = "添加商家")
    public ResultData<String> addmerchant(@RequestBody Merchant merchant){
        System.out.println(merchant.toString());
        int i = merchantService.add(merchant);
        return ResultData.success("成功插入记录，返回值："+i);
    }

    //删除商家
    @DeleteMapping(value = "/merchant/del/{id}")
    @Operation(summary = "删除商家", description = "删除商家")
    public ResultData<Integer> deletemerchant(@PathVariable("id") Integer id) {
        Integer i=merchantService.delete(id);
        return ResultData.success(i);
    }


    //修改商家
    @PutMapping(value = "/merchant/update")
    @Operation(summary = "修改商家", description = "修改商家")
    public ResultData<String> updatemerchant(@RequestBody Merchant merchant){
        int i = merchantService.update(merchant);
        return ResultData.success("成功修改记录，返回值："+i);
    }

    //查询商家
    @GetMapping(value = "/merchant/get/{id}")
    @Operation(summary = "查询商家", description = "查询商家")
    public ResultData<Merchant> getById(@PathVariable("id") Integer id){
        Merchant merchant=merchantService.getById(id);
        return ResultData.success(merchant);
    }

    //查询所有商家
    @GetMapping(value = "/merchant/getall")
    @Operation(summary = "查询所有商家", description = "查询所有商家")
    public ResultData<List<Merchant>> getAll(){
        return ResultData.success(merchantService.getAll());
    }

    //分页查询所有商家
    @GetMapping(value = "/merchant/paginationQuery/getall/{currentPage}")
    @Operation(summary = "分页的进行商家的查询", description = "分页的进行商家的查询")
    public ResultData<PaginationResult<Merchant>> paginationQuery(@PathVariable("currentPage") Integer currentPage){
        return ResultData.success(merchantService.myPaginationQuery(currentPage));
    }

}
